import { useUserStore } from '../store/userStore';
import { Navigate, useLocation } from 'react-router-dom';
import { ReactNode } from 'react';

interface AuthRouteProps {
  children: ReactNode;
}

export const AuthRoute = ({ children }: AuthRouteProps) => {
  const { userInfo } = useUserStore();
  const location = useLocation();

  if (!userInfo?.sessionId) {
    // 未登录，重定向到登录页，并保存当前路径
    return <Navigate to="/login" state={{ from: location.pathname }} replace />;
  }

  return <>{children}</>;
}; 